package cn.ljy.mes.service.impl;

import cn.ljy.common.exception.model.base.MyRollBackException;
import cn.ljy.mes.dao.mapper.CountMapper;
import cn.ljy.mes.dao.mapper.MesProductionOrderAuditLogMapper;
import cn.ljy.mes.service.CountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Validated
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor= MyRollBackException.class)
@Slf4j
public class ICountService implements CountService {

    @Autowired
    private CountMapper countMapper;
    @Autowired
    private MesProductionOrderAuditLogMapper productionOrderAuditLogMapper;

    @Override
    public List<Map<String, Object>> getProductModelsOrderByOrderCountDesc(Integer limit) {
        if(limit==null){
            limit=5;
        }
        return countMapper.getProductModelsOrderByOrderCountDesc(limit);
    }

    @Override
    public List<Map<String, Object>> getProductionOrderStatusCountWithPriorityOrder() {
        return countMapper.getProductionOrderStatusCountWithPriorityOrder();
    }

    @Override
    public List<Map<String, Object>> getShopCarOrderStatusCountWithPriorityOrder() {
        return countMapper.getShopCarOrderStatusCountWithPriorityOrder();
    }

    @Override
    public Map<String, Object> getFirstApprovalPassedOrderCountAndOrderCount() {
        int firstApprovalPassedOrderCount = productionOrderAuditLogMapper.getFirstApprovalPassedOrderCount();
        int orderCount = productionOrderAuditLogMapper.getUniqueOrderCount();
        Map<String,Object> map=new HashMap<>();
        map.put("firstApprovalPassedOrderCount",firstApprovalPassedOrderCount);
        map.put("orderCount",orderCount);
        return map;
    }
}
